package com.example.app3.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.example.app3.R;
import com.example.app3.recyclerView.ContentActivity;
import com.example.app3.ui.MyView;
import com.example.app3.util.Init;

public class HomeFragment extends Fragment {


    private MyView myView;
    private int position;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_home, container, false);

//        索引从0开始
        position = getActivity().getIntent().getIntExtra("position", -1);

        myView = root.findViewById(R.id.myView);

        //点击不同的行，切换不同的主题
        switch (position){
            case 0:
            case 1:
            case 2:myView.setContents(Init.initDianMing()); break;
            case 4:myView.setContents(Init.initEat()); break;
            case 5:myView.setContents(Init.initGo()); break;
        }


        Button button = root.findViewById(R.id.button5);
        button.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), ContentActivity.class);
            startActivity(intent);
        });

        return root;
    }
}